package com.wnhz.work.yz.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.google.gson.Gson;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.Finish1;
import com.wnhz.work.yz.bean.GroupDetailBean;
import com.wnhz.work.yz.bean.PersonBean;
import com.wnhz.work.yz.utils.CalUtil;
import com.wnhz.work.yz.utils.CountDownTimerUtils;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;
import com.wnhz.work.yz.view.CircularImage;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GroupDetailsActivity extends BaseActivity implements View.OnClickListener {
    private SwipeMenuListView listView, sm_manager, sm_person;
    private LinearLayout fuze;
    private LinearLayout add_manager, add_person;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(Finish1 event) {
        finish();
    }


    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);//反注册EventBus
        super.onDestroy();
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_group_details);
        initData();
        initTitle();
        initView();
        EventBus.getDefault().register(this);
       // MyApplication.getInstance().addDestoryActivity(this, "groupDetails");
    }

    private CircularImage manager_img;
    private TextView manager_name, manager_phone, manager_class;

    private void initView() {
        listView = (SwipeMenuListView) findViewById(R.id.listView);
        manager_class = (TextView) findViewById(R.id.manager_class);
        manager_phone = (TextView) findViewById(R.id.manager_phone);
        manager_name = (TextView) findViewById(R.id.manager_name);
        manager_img = (CircularImage) findViewById(R.id.manager_img);
        sm_person = (SwipeMenuListView) findViewById(R.id.sm_person);
        sm_manager = (SwipeMenuListView) findViewById(R.id.sm_manager);
        fuze = (LinearLayout) findViewById(R.id.fuze);
        fuze.setOnClickListener(this);
        add_manager = (LinearLayout) findViewById(R.id.add_manager);
        add_manager.setOnClickListener(this);
        add_person = (LinearLayout) findViewById(R.id.add_person);
        add_person.setOnClickListener(this);

    }

    private int dp2px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("团队");
//        title.setTextSize(20);
        title.setTextColor(getResources().getColor(R.color.main_color));
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        TextView submit = (TextView) findViewById(R.id.submit);
        submit.setText("申请列表");
        submit.setTextColor(getResources().getColor(R.color.main_color));
        submit.setOnClickListener(this);
        submit.setVisibility(View.VISIBLE);

    }

    private String teamId;

    private void initData() {
        teamId = getIntent().getStringExtra("teamId");

    }

    @Override
    protected void onResume() {
        upLoad();
        super.onResume();
    }

    private GroupDetailBean.InfoEntity infoEntity = new GroupDetailBean.InfoEntity();
    private List<GroupDetailBean.InfoEntity> infos = new ArrayList<>();

    private void upLoad() {
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("team_id", teamId);
        showDialog();

        XUtil.Post(Url.TEAM_MYTEAM, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", teamId + "onSuccess:= " + result);
                infos.clear();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        Gson gson = new Gson();
                        GroupDetailBean bean = gson.fromJson(result, GroupDetailBean.class);
                        infoEntity = bean.getInfo();
                        infos.add(infoEntity);
                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                setData();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                Log.i("----", teamId + "onSuccess:= erererere"+ex.toString());
                closeDialog();
            }
        });
    }

    private int is_manager = -1;

    private void setData() {

        try {
            if (infoEntity.getMain_user().getTelephone().equals(MyApplication.getInstance().getUserBean().getPhone())) {
                is_manager = 1;
            } else {
                is_manager = 0;
            }

            for (int i = 0; i < infoEntity.getManage_user().size(); i++) {
                if (infoEntity.getManage_user().get(i).getTelephone().equals(MyApplication.getInstance().getUserBean().getPhone())) {
                    is_manager = 1;
                }
            }
            if (is_manager == 1) {
                add_manager.setVisibility(View.VISIBLE);
                add_person.setVisibility(View.VISIBLE);
            } else {
                add_manager.setVisibility(View.GONE);
                add_person.setVisibility(View.GONE);

            }
        } catch (Exception e) {

        }
        x.image().bind(manager_img, infoEntity.getMain_user().getUser_img());
        //   private TextView manager_name, manager_phone, manager_class;
        manager_name.setText(infoEntity.getMain_user().getUser_name());
        manager_phone.setText(infoEntity.getMain_user().getTelephone());
        manager_class.setText(infoEntity.getMain_user().getClassname());
        initSwipList();
        initManagerList();
        initPersonList();
    }

    private void initPersonList() {
        personAdapter = new PersonAdapter();
        sm_person.setAdapter(personAdapter);
        if ("1".equals(infoEntity.getMain_user().getIs_mine())) {
            canTiChu(sm_person, false);
        }

    }

    private void canTiChu(SwipeMenuListView list, final boolean flag) {
        SwipeMenuCreator creater = getCreater("移除");
        list.setMenuCreator(creater);
        list.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(final int position, SwipeMenu menu, int index) {
                switch (index) {
                    case 0:
                        showDialogv7("确定移除TA吗？", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                updeletePerson(position, flag);
                            }
                        });
                        break;

                    default:
                        break;
                }
                return false;
            }
        });
    }

    private void updeletePerson(final int position, final boolean flag) {
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("team_id", teamId);
        if (flag) {
            map.put("user_id", infoEntity.getManage_user().get(position).getUser_id());
        } else {
            map.put("user_id", infoEntity.getGeneral_user().get(position).getUser_id());
        }
        showDialog();
      /*  Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, ":" + value + "\n");
            }
        }*/
        XUtil.Post(Url.TEAM_EXITTEAMBYMANAGE, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                infos.clear();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        MyToast(info);
                        upLoad();
                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
            }
        });

    }

    private void initManagerList() {
        managerAdapter = new ManagerAdapter();
        sm_manager.setAdapter(managerAdapter);
        //    if ("1".equals(infoEntity.getMain_user().getIs_mine())) {
        canTiChu(sm_manager, true);
        //  }

    }

    private PersonAdapter personAdapter;

    class PersonAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return infoEntity.getGeneral_user() == null ? 0 : infoEntity.getGeneral_user().size();
        }

        @Override
        public Object getItem(int position) {
            return infoEntity.getGeneral_user().get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                holder = new Holder();
                convertView = View.inflate(GroupDetailsActivity.this, R.layout.item_rv_manager, null);
                holder.head_img = (CircularImage) convertView.findViewById(R.id.head_img);
                holder.yaoqinging = (TextView) convertView.findViewById(R.id.yaoqinging);
                holder.head_name = (TextView) convertView.findViewById(R.id.head_name);
                holder.max_ll = (LinearLayout) convertView.findViewById(R.id.max_ll);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }

            x.image().bind(holder.head_img, infoEntity.getGeneral_user().get(position).getUser_img());
            holder.head_name.setText(infoEntity.getGeneral_user().get(position).getUser_name());
            if ("1".equals(infoEntity.getGeneral_user().get(position).getStatus())) {
                holder.yaoqinging.setVisibility(View.GONE);
                holder.head_name.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(GroupDetailsActivity.this, GroupPersonInfoActivity.class);

                        intent.putExtra("user_id", infoEntity.getGeneral_user().get(position).getUser_id());
                        intent.putExtra("telephone", infoEntity.getGeneral_user().get(position).getTelephone());
                        intent.putExtra("user_name", infoEntity.getGeneral_user().get(position).getUser_name());
                        intent.putExtra("user_img", infoEntity.getGeneral_user().get(position).getUser_img());
                        intent.putExtra("is_mine", infoEntity.getGeneral_user().get(position).getIs_mine());
                        intent.putExtra("team_id", teamId);
                        intent.putExtra("classname", infoEntity.getGeneral_user().get(position).getClassname());
                        intent.putExtra("mygroup", infoEntity.getTeam_name());
                        intent.putExtra("howgroup", infoEntity.getMain_user().getUser_name());
                        intent.putExtra("status", "1");
                        intent.putExtra("is_manager", is_manager);
                        startActivity(intent);
                    }
                });
            } else if ("2".equals(infoEntity.getGeneral_user().get(position).getStatus())) {
                holder.yaoqinging.setVisibility(View.VISIBLE);
            }
            return convertView;
        }

        class Holder {
            CircularImage head_img;
            TextView yaoqinging;
            TextView head_name;
            LinearLayout max_ll;
        }
    }

    private ManagerAdapter managerAdapter;

    class ManagerAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            Log.e("sadasd", infoEntity.getManage_user() + "---");
            return infoEntity.getManage_user() == null ? 0 : infoEntity.getManage_user().size();
        }

        @Override
        public Object getItem(int position) {
            return infoEntity.getManage_user().get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            Holder holder;

            if (convertView == null) {
                holder = new Holder();
                convertView = View.inflate(GroupDetailsActivity.this, R.layout.item_rv_manager, null);
                holder.head_img = (CircularImage) convertView.findViewById(R.id.head_img);
                holder.head_name = (TextView) convertView.findViewById(R.id.head_name);
                holder.max_ll = (LinearLayout) convertView.findViewById(R.id.max_ll);
                holder.yaoqinging = (TextView) convertView.findViewById(R.id.yaoqinging);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            x.image().bind(holder.head_img, infoEntity.getManage_user().get(position).getUser_img());
            holder.head_name.setText(infoEntity.getManage_user().get(position).getUser_name());
            if ("1".equals(infoEntity.getManage_user().get(position).getStatus())) {
                holder.yaoqinging.setVisibility(View.GONE);
                holder.head_name.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(GroupDetailsActivity.this, GroupPersonInfoActivity.class);
                        intent.putExtra("user_id", infoEntity.getManage_user().get(position).getUser_id());
                        intent.putExtra("telephone", infoEntity.getManage_user().get(position).getTelephone());
                        intent.putExtra("user_name", infoEntity.getManage_user().get(position).getUser_name());
                        intent.putExtra("user_img", infoEntity.getManage_user().get(position).getUser_img());
                        intent.putExtra("is_mine", infoEntity.getManage_user().get(position).getIs_mine());
                        intent.putExtra("classname", infoEntity.getManage_user().get(position).getClassname());
                        intent.putExtra("mygroup", infoEntity.getTeam_name());
                        intent.putExtra("team_id", teamId);
                        intent.putExtra("howgroup", infoEntity.getMain_user().getUser_name());
                        intent.putExtra("status", "0");
                        intent.putExtra("is_manager", is_manager);
                        startActivity(intent);
                    }
                });

            } else if ("2".equals(infoEntity.getManage_user().get(position).getStatus())) {
                holder.yaoqinging.setVisibility(View.VISIBLE);
            }

            return convertView;
        }

        class Holder {
            CircularImage head_img;
            TextView yaoqinging;
            TextView head_name;
            LinearLayout max_ll;
        }
    }

    private TeamAdapter teamAdapter;

    private class TeamAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return infos.size();
        }

        @Override
        public Object getItem(int position) {
            return infos.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                holder = new Holder();
                convertView = View.inflate(GroupDetailsActivity.this, R.layout.team_name, null);
                holder.head_img = (CircularImage) convertView.findViewById(R.id.head_img);
                holder.team_code = (ImageView) convertView.findViewById(R.id.team_code);
                holder.team_name = (TextView) convertView.findViewById(R.id.team_name);
                holder.team_num = (TextView) convertView.findViewById(R.id.team_num);
                holder.creat_time = (TextView) convertView.findViewById(R.id.creat_time);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            x.image().bind(holder.head_img, infos.get(position).getLogo_img());
            x.image().bind(holder.team_code, infos.get(position).getQrcode());
            holder.team_name.setText(infos.get(position).getTeam_name());
            holder.team_num.setText(infos.get(position).getTeamCounts());
            holder.creat_time.setText("创建于：" + infos.get(position).getCreate_at());
            return convertView;
        }

        class Holder {
            private CircularImage head_img;
            private ImageView team_code;
            private TextView team_name, team_num, creat_time;
        }
    }

    public SwipeMenuCreator getCreater(final String type) {
        SwipeMenuCreator creater = new SwipeMenuCreator() {
            @Override
            public void create(SwipeMenu menu) {


                //同理create删除item
                SwipeMenuItem deleteItem = new SwipeMenuItem(GroupDetailsActivity.this);
                // set item background
                deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
                // set item width
                deleteItem.setWidth(dp2px(90));
                // set item title
                deleteItem.setTitle(type);
                // set item title fontsize
                deleteItem.setTitleSize(18);
                // set item title font color
                deleteItem.setTitleColor(Color.WHITE);
                // set a icon
                //    deleteItem.setIcon(R.mipmap.ic_delete);
                // add to menu
                menu.addMenuItem(deleteItem);
            }
        };
        return creater;
    }

    private void initSwipList() {
        teamAdapter = new TeamAdapter();
        listView.setAdapter(teamAdapter);

        if ("1".equals(infoEntity.getMain_user().getIs_mine())) {
            SwipeMenuCreator creater = getCreater("解散");
            listView.setMenuCreator(creater);
            listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(final int position, SwipeMenu menu, int index) {
                    switch (index) {

                        case 0:
                            //删除的逻辑
                            final AlertDialog.Builder builder = new AlertDialog.Builder(GroupDetailsActivity.this);
                            View view = View.inflate(GroupDetailsActivity.this, R.layout.dialog_cancle_team, null);
                            TextView queding = (TextView) view.findViewById(R.id.queding);
                            TextView cancel = (TextView) view.findViewById(R.id.cancel);
                            final TextView sendMsg = (TextView) view.findViewById(R.id.sendMsg);
                            final EditText editMsg = (EditText) view.findViewById(R.id.editMsg);
                            builder.setView(view);
                            final AlertDialog show = builder.show();
                            Window dialogWindow = show.getWindow();
                            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                            dialogWindow.setGravity(Gravity.CENTER);
                            // lp.x = 100; // 新位置X坐标
                            dialogWindow.setAttributes(lp);
                            queding.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    if (editMsg.getText().toString().equals("")) {
                                        MyToast("请输入验证码");
                                        return;
                                    }
                                    show.dismiss();
                                    updelete(editMsg.getText().toString());
                                }
                            });
                            sendMsg.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(sendMsg, 60000, 1000);
                                    mCountDownTimerUtils.start();
                                    sendMsg();
                                }
                            });
                            cancel.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    show.dismiss();
                                }
                            });
                            break;

                        default:
                            break;
                    }
                    return false;
                }
            });
        }
    }

    private void sendMsg() {
        Map<String, Object> map = new HashMap<>();
        map.put("phone", MyApplication.getInstance().getUserBean().getPhone());
        map.put("type", "4");
        map.put("other", CalUtil.Cal());
        showDialog();
        XUtil.Post(Url.PHONEEXISTSENDCODE, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        MyToast(info);

                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
            }
        });
    }

    private void updelete(String msg) {
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("code", msg);
        map.put("team_id", teamId);
        showDialog();
        XUtil.Post(Url.TEAM_QUITTEAM, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        MyToast(info);
                        finish();
                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
            }
        });

    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                intent = new Intent(this, OtherAddGroupActivity.class);
                intent.putExtra("team_id", teamId);
                intent.putExtra("team_name", infoEntity.getTeam_name());
                startActivity(intent);
                break;
            case R.id.fuze:
                intent = new Intent(GroupDetailsActivity.this, GroupPersonInfoActivity.class);
                intent.putExtra("user_id", infoEntity.getMain_user().getUser_id());
                intent.putExtra("telephone", infoEntity.getMain_user().getTelephone());
                intent.putExtra("user_name", infoEntity.getMain_user().getUser_name());
                intent.putExtra("user_img", infoEntity.getMain_user().getUser_img());
                intent.putExtra("is_mine", infoEntity.getMain_user().getIs_mine());
                intent.putExtra("classname", infoEntity.getMain_user().getClassname());
                intent.putExtra("mygroup", infoEntity.getTeam_name());
                intent.putExtra("howgroup", infoEntity.getMain_user().getUser_name());
                intent.putExtra("team_id", teamId);
                intent.putExtra("is_manager", is_manager);
                startActivity(intent);
                break;
            case R.id.add_manager:
                startActivityForResult(new Intent(this, GroupInviteActivity.class)
                                .putExtra("groupId", teamId)
                                .putExtra("img", infoEntity.getQrcode())
                                .putExtra("name", infoEntity.getTeam_name())
                        , ADDMANAGER);
                break;
            case R.id.add_person:
                startActivityForResult(new Intent(this, GroupInviteActivity.class)
                                .putExtra("groupId", teamId)
                                .putExtra("img", infoEntity.getQrcode())
                                .putExtra("name", infoEntity.getTeam_name())
                        , ADDGENERAL);
                break;
        }
    }

    private static final int ADDMANAGER = 333;
    private static final int ADDGENERAL = 444;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ADDMANAGER:
                if (resultCode == RESULT_OK) {
                    PersonBean.InfoEntity bean = (PersonBean.InfoEntity) data.getSerializableExtra("bean");
                    upLoadAddPerson("1", bean.getUser_id());
                }
                break;
            case ADDGENERAL:
                if (resultCode == RESULT_OK) {
                    PersonBean.InfoEntity bean = (PersonBean.InfoEntity) data.getSerializableExtra("bean");
                    upLoadAddPerson("0", bean.getUser_id());
                }
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void upLoadAddPerson(String s, String user_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("user_id", user_id);
        map.put("team_id", teamId);
        map.put("level", s);
        showDialog();
      /*  Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, ":" + value + "\n");
            }
        }*/
        XUtil.Post(Url.TEAM_INVITEADDTEAM, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        MyToast(info);
                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
            }
        });
    }
}
